package com.leetcode.Offer;

import java.util.Arrays;
import java.util.Comparator;

public class JZ45 {
    public String minNumber(int[] nums) {
        if (nums==null||nums.length==0){
            return "";
        }

        Integer[] integers = new Integer[nums.length];
        int a=0;
        for (int num : nums) {
            integers[a++]=num;
        }
        //System.arraycopy(nums,0,integers,0,nums.length);
        Arrays.sort(integers,(x,y)->(x+""+y).compareTo(y+""+x));//注意

        StringBuilder stringBuilder = new StringBuilder();
        for (Integer integer : integers) {
            stringBuilder.append(integer);
        }
        return stringBuilder.toString();
    }

    public String minNumber2(int[] nums) {
        if (nums==null||nums.length==0){
            return "";
        }

        String[] strings = new String[nums.length];
        int a=0;
        for (int num : nums) {
            strings[a++]=String.valueOf(num);
        }
        Arrays.sort(strings,(x,y)->(x+y).compareTo(y+x));//注意

        StringBuilder stringBuilder = new StringBuilder();
        for (String s : strings) {
            stringBuilder.append(s);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new JZ45().minNumber2(new int[]{3,30,34,5,9}));

    }
}
